package com.gasolinator.a.app.db;

import android.app.ProgressDialog;
import android.os.AsyncTask;
import com.gasolinator.a.GasolinatorActivity;

import java.util.Map;

/**
 * Created by IntelliJ IDEA.
 * User: fjhidalgo
 * Date: 5/01/12
 * Time: 10:06
 * To change this template use File | Settings | File Templates.
 */
public class ChargeGasAsynkTask extends AsyncTask<String, String, Map<Integer, String>>
{
    private GasolinatorActivity activity;
    private ProgressDialog dialog = null;

    public ChargeGasAsynkTask(GasolinatorActivity gasolinatorActivity)
    {
        activity=gasolinatorActivity;
    }

    @Override
    protected Map<Integer, String> doInBackground(String... strings)
    {
        return GasolinatorDBSearcher.getGasStations(activity);
    }


    @Override
    protected void onPreExecute() {
        String message = "Cargando Gasolineras -beta-";
        dialog = new ProgressDialog(activity);
        dialog.setIndeterminate(true);
        dialog.setCancelable(true);
        dialog.setCanceledOnTouchOutside(true);
        dialog.setMessage(message);
        dialog.show();
    }

    @Override
    protected void onPostExecute(Map<Integer, String> response) {
        dialog.dismiss();
        activity.setGasStations(response);
    }

    @Override
    protected void onProgressUpdate(String... values) {

    }

    @Override
    protected void onCancelled() {
    }
}
